﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Vowei.Core.Models;
using Vowei.Core.Scm;
using Vowei.Data.Models;

namespace vowei.test
{
    [TestClass]
    public class SvnIntergrationTests : TestBase
    {
        private void FormatSvnChangeListTestHelper(string clText, string[] expected)
        {
            var project = new Project()
            {
                ScmUrl = "http://shiyimin:88/svn/vowei/",
                ScmType = "Svn",
                Title = "施懿民机器上的项目",
                StartDate = DateTime.Now,
                Owner = Setting.DefaultUserName
            };

            var formatter = new SvnLogFormatter();
            var actual = formatter.FormatChangedLog(clText, project);

            Assert.AreEqual(expected.Length, actual.Length);
            for (int i = 0; i < expected.Length; ++i)
            {
                Assert.AreEqual(expected[i], actual[i]);
            }
        }

        [TestMethod]
        public void FormatSvnChangeListWithoutRenameTest()
        {
            var clText = "U   vowei/trunk/src/vowei.web/vowei.web.ui/Controls/GeometryArea.xaml\n" +
                         "U   vowei/trunk/src/vowei.web/vowei web ui/Controls/GeometryArea.xaml.cs\n" +
                         "U   vowei/trunk/src/vowei.web/vowei.web.ui/MainPage.xaml\n" +
                         "U   vowei/trunk/src/vowei.web/vowei.web.ui/MainPage.xaml.cs\n" +
                         "U   vowei/trunk/src/vowei.web/vowei.web.ui/NavigationManager.cs\n" +
                         "D   vowei/trunk/src/vowei.web/vowei.web.ui/ServiceDispatcher.cs\n" +
                         "U   vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/GeometryAreaModel.cs\n" +
                         "A   vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/IContextMenuHost.cs\n" +
                         "U   vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/MainPageModel.cs\n" +
                         "U   vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/NavigatableModel.cs\n" +
                         "_U   vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel1.cs\n" +
                         "UU   vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel2.cs\n" +
                         "U   vowei/trunk/src/vowei.web/vowei.web.ui/vowei.web.ui.csproj";
            var expected = new string[] {
                "<a class=\"scm_file_changed\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/Controls/GeometryArea.xaml\">vowei/trunk/src/vowei.web/vowei.web.ui/Controls/GeometryArea.xaml</a>" ,
                "<a class=\"scm_file_changed\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei web ui/Controls/GeometryArea.xaml.cs\">vowei/trunk/src/vowei.web/vowei web ui/Controls/GeometryArea.xaml.cs</a>" ,
                "<a class=\"scm_file_changed\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/MainPage.xaml\">vowei/trunk/src/vowei.web/vowei.web.ui/MainPage.xaml</a>" ,
                "<a class=\"scm_file_changed\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/MainPage.xaml.cs\">vowei/trunk/src/vowei.web/vowei.web.ui/MainPage.xaml.cs</a>" ,
                "<a class=\"scm_file_changed\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/NavigationManager.cs\">vowei/trunk/src/vowei.web/vowei.web.ui/NavigationManager.cs</a>" ,
                "<a class=\"scm_deleted\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/ServiceDispatcher.cs\">vowei/trunk/src/vowei.web/vowei.web.ui/ServiceDispatcher.cs</a>" ,
                "<a class=\"scm_file_changed\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/GeometryAreaModel.cs\">vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/GeometryAreaModel.cs</a>" ,
                "<a class=\"scm_added\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/IContextMenuHost.cs\">vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/IContextMenuHost.cs</a>" ,
                "<a class=\"scm_file_changed\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/MainPageModel.cs\">vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/MainPageModel.cs</a>" ,
                "<a class=\"scm_file_changed\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/NavigatableModel.cs\">vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/NavigatableModel.cs</a>" ,                
                "<a class=\"scm_property_changed\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel1.cs\">vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel1.cs</a>" ,
                "<a class=\"scm_changed\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel2.cs\">vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel2.cs</a>" ,
                "<a class=\"scm_file_changed\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/vowei.web.ui.csproj\">vowei/trunk/src/vowei.web/vowei.web.ui/vowei.web.ui.csproj</a>"
            };

            FormatSvnChangeListTestHelper(clText, expected);
        }

        [TestMethod]
        public void FormatSvnChangeListRenameTest()
        {
            var clText = "A +  vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel.cs\n" +
                         "    (from vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel4.cs:r63)\n" +
                         "D   vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel4.cs";
            
            var expected = new string[] {                
                "<a class=\"scm_renamed\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel.cs\">vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel.cs</a><br />" +
                "    (from <a class=\"scm_deleted\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel4.cs\">vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel4.cs</a>:r63)<br />" ,
                "<a class=\"scm_deleted\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel4.cs\">vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel4.cs</a>"                 
            };

            FormatSvnChangeListTestHelper(clText, expected);
        }

        [TestMethod]
        public void FormatSvnChangeListTest()
        {
            var clText = "U   vowei/trunk/src/vowei.web/vowei.web.ui/Controls/GeometryArea.xaml\n" +
                         "U   vowei/trunk/src/vowei.web/vowei web ui/Controls/GeometryArea.xaml.cs\n" +
                         "U   vowei/trunk/src/vowei.web/vowei.web.ui/MainPage.xaml\n" +
                         "U   vowei/trunk/src/vowei.web/vowei.web.ui/MainPage.xaml.cs\n" +
                         "U   vowei/trunk/src/vowei.web/vowei.web.ui/NavigationManager.cs\n" +
                         "D   vowei/trunk/src/vowei.web/vowei.web.ui/ServiceDispatcher.cs\n" +
                         "U   vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/GeometryAreaModel.cs\n" +
                         "A   vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/IContextMenuHost.cs\n" +
                         "U   vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/MainPageModel.cs\n" +
                         "U   vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/NavigatableModel.cs\n" +
                         "A +  vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel.cs\n" +
                         "    (from vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel4.cs:r63)\n" +
                         "D   vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel4.cs\n" +
                         "_U   vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel1.cs\n" +
                         "UU   vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel2.cs\n" +
                         "U   vowei/trunk/src/vowei.web/vowei.web.ui/vowei.web.ui.csproj";

            var expected = new string[] {
                "<a class=\"scm_file_changed\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/Controls/GeometryArea.xaml\">vowei/trunk/src/vowei.web/vowei.web.ui/Controls/GeometryArea.xaml</a>" ,
                "<a class=\"scm_file_changed\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei web ui/Controls/GeometryArea.xaml.cs\">vowei/trunk/src/vowei.web/vowei web ui/Controls/GeometryArea.xaml.cs</a>" ,
                "<a class=\"scm_file_changed\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/MainPage.xaml\">vowei/trunk/src/vowei.web/vowei.web.ui/MainPage.xaml</a>" ,
                "<a class=\"scm_file_changed\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/MainPage.xaml.cs\">vowei/trunk/src/vowei.web/vowei.web.ui/MainPage.xaml.cs</a>" ,
                "<a class=\"scm_file_changed\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/NavigationManager.cs\">vowei/trunk/src/vowei.web/vowei.web.ui/NavigationManager.cs</a>" ,
                "<a class=\"scm_deleted\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/ServiceDispatcher.cs\">vowei/trunk/src/vowei.web/vowei.web.ui/ServiceDispatcher.cs</a>" ,
                "<a class=\"scm_file_changed\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/GeometryAreaModel.cs\">vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/GeometryAreaModel.cs</a>" ,
                "<a class=\"scm_added\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/IContextMenuHost.cs\">vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/IContextMenuHost.cs</a>" ,
                "<a class=\"scm_file_changed\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/MainPageModel.cs\">vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/MainPageModel.cs</a>" ,
                "<a class=\"scm_file_changed\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/NavigatableModel.cs\">vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/NavigatableModel.cs</a>" ,
                "<a class=\"scm_renamed\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel.cs\">vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel.cs</a><br />" +
                "    (from <a class=\"scm_deleted\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel4.cs\">vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel4.cs</a>:r63)<br />" ,
                "<a class=\"scm_deleted\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel4.cs\">vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel4.cs</a>" ,
                "<a class=\"scm_property_changed\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel1.cs\">vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel1.cs</a>" ,
                "<a class=\"scm_changed\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel2.cs\">vowei/trunk/src/vowei.web/vowei.web.ui/ViewModels/ThemeCollectionModel2.cs</a>" ,
                "<a class=\"scm_file_changed\" href=\"http://shiyimin:88/svn/vowei/vowei/trunk/src/vowei.web/vowei.web.ui/vowei.web.ui.csproj\">vowei/trunk/src/vowei.web/vowei.web.ui/vowei.web.ui.csproj</a>"
            };

            FormatSvnChangeListTestHelper(clText, expected);
        }
    }
}
